/*
 *懒人CSS Bate V0.09
 *作者：懒人建站 http://www.51xuediannao.com/
 *2013-10-01———
*/

$(function(){
	
	/*选项卡练习*/
	function LrTab(options){
		this.options = $.extend({
				Event:'click',			//事件	click / mouseenter
				obj:'.js-tab'		//目标对象盒子
			},options)
	}
	
	LrTab.prototype.show = function(){
		var that = this,
			thatOpts = this.options,
			tabHead = thatOpts.obj;
			
		$(tabHead).each(function(index, element) {
			
			$(this).on(thatOpts.Event,"li",function(){
				var that =$(this),
					index = that.index();
				that.addClass("cur").siblings("li").removeClass("cur");
				that.closest(thatOpts.obj).next("div").children("div").eq(index).show().siblings("div").hide();
			})
        });	
	};

    var test = new LrTab().show();

	

	/*
	 * 下拉菜单
	 * 长征 练习	Event,obj,X
	 * 如：var ddMenu1 = new ddMenu('click',".bl-ddmenu",2).Show();
	*/
	
	function ChangClass(options){
		this.options = $.extend({
				Event:'click',			//事件
				obj:'.bl-ddmenu',		//目标对象盒子
				target:'.ddmenu-btn',	//目标对象盒子
				type:'ddMenu',
				X:0,					//X轴偏移情况
				loadFun:function(){}
			},options||{} ),
		this.Event 	= this.options.Event,	
		this.obj 	= this.options.obj,				
		this.X = (this.options.X) ? this.options.X : 0
	}
	
	function conPtop(obj,H,X){
		obj.find(".bl-ddmenu-con").css({"padding-top":H+X});
	}

	ChangClass.prototype.clickShow = function()
	{
		var thisObj = this.obj,
			thisOpts = this.options;
		
		$(thisObj).each(function(index, element) {
            var that = $(this),
				btn	= that.children(".ddmenu-btn"),
				con = that.children(".bl-ddmenu-con"),
				W = btn.outerWidth(),
				H = btn.outerHeight();
				
			conPtop(that,H,thisOpts.X);
			
			if(thisOpts.Event=='click'){
				that.on(thisOpts.Event,thisOpts.target,
					function(){
						if(!that.hasClass("cur")){
							$(".bl-ddmenu").removeClass("cur").css({"z-index":1000});
							that.addClass("cur").css({"z-index":1001});
						}else{
							that.removeClass("cur").css({"z-index":1000});
						}
					
					thisOpts.loadFun();
					return false	
				})
			}
			else
			{
				that.hover(
					function(){
						that.addClass("cur").css({"z-index":1001});
					},
					function(){
						that.removeClass("cur").css({"z-index":1000});
					}
				);	
			}
			
        });
		
		//单击空白消失
		$(document).click(function(e){
		  if(e.target.className.indexOf("bl-ddmenu")==-1){
			  $(thisObj).removeClass("cur");
		  } 
		});
	};
	
	var changClass1 = new ChangClass({
			Event:'hover',
			X:-1		
		}).clickShow();
	
});


/*var opts={
		Event:'click',
		obj:".bl-ddmenu",
		X:0
	};
$.extend(opts,options);*/